package com.pf.common.utils;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * @author PanFei
 * @version 1.0.0
 * @createTime 2023/4/25 21:04
 */
public class CustomStringUtils {

    /**
     * 将对象转为String
     *
     * @param obj
     * @return
     */
    public static String object2Str(Object obj) {
        if (obj == null) {
            return null;
        }
        return String.valueOf(obj);
    }

    /**
     * 将字符串拆分为list
     *
     * @param str
     * @param splitRegex
     * @return
     */
    public static List<String> str2DeduplicationList(String str, String splitRegex) {
        if (StringUtils.isBlank(str)) {
            return Lists.newArrayList();
        }
        return Lists.newArrayList(Sets.newHashSet(str.split(splitRegex)));
    }

    /**
     * 将字符串拆分为list，去重
     *
     * @param str
     * @return
     */
    public static List<String> str2DeduplicationList(String str) {
        return str2DeduplicationList(str, ",");
    }
}
